package cn.lystudio.rohm_time_op.controller.appApi;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.util.SaResult;
import cn.hutool.core.util.ObjectUtil;
import cn.lystudio.rohm_time_op.entity.po.QrTypePO;
import cn.lystudio.rohm_time_op.entity.po.USMQrTypePO;
import cn.lystudio.rohm_time_op.service.QrTypeService;
import cn.lystudio.rohm_time_op.service.USMQrTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/app-api/qrtype")
@CrossOrigin
@SaIgnore
@Slf4j
public class AppQrTypeController {
    private QrTypeService qrTypeService;
    private USMQrTypeService usmQrTypeService;
    @Lazy
    @Autowired
    public void setQrTypeService(QrTypeService qrTypeService) {
        this.qrTypeService = qrTypeService;
    }
    @Autowired
    public void setUsmQrTypeService(USMQrTypeService usmQrTypeService) {
        this.usmQrTypeService = usmQrTypeService;
    }


    @GetMapping("/getQrType")
    public SaResult getQrType(Integer qrTypeID){
        QrTypePO qrType = qrTypeService.get1ByID(qrTypeID);
        if(ObjectUtil.isEmpty(qrType)){
            return  SaResult.error("QR格式设定异常");
        }
        return SaResult.data(qrType);
    }

    @GetMapping("/getUSMQrType")
    public SaResult getUSMQrType(){
        USMQrTypePO usmQrType = usmQrTypeService.getUSMQrType();
        if(ObjectUtil.isEmpty(usmQrType)) return SaResult.error("USM二维码设置异常");
        return SaResult.data(usmQrType);
    }

    @GetMapping("/getUSMChipQRType")
    public SaResult getUSMChipQRType(){
        USMQrTypePO usmChipQrType = usmQrTypeService.getUSMChipQRType();
        if(ObjectUtil.isEmpty(usmChipQrType)) return SaResult.error("USM素子二维码设置异常");
        return SaResult.data(usmChipQrType);
    }
}
